﻿#if NET6_0_OR_GREATER

using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using T.ServiceFramework.Service;

namespace T.SF.Console.HttpHost
{
    [WebApiExceptionFilter]
    public class CommonController : ControllerBase
    {
        [HttpPut]
        [HttpPost]
        [HttpGet]
        [HttpDelete]
        [HttpHead]
        [HttpOptions]
        [HttpPatch]
        [AllowAnonymous]
        public async Task<object> Execute(Dictionary<string, string> data)
        {
            return await WebHostService.Current.Invoker.InvokeAsync(base.HttpContext, data);
        }

        [HttpPut]
        [HttpPost]
        [HttpGet]
        [HttpDelete]
        [HttpHead]
        [HttpOptions]
        [HttpPatch]
        [AllowAnonymous]        
        [Consumes("application/json")]
        public async Task<object> Execute([FromBody] Hashtable data)        
        {
            Dictionary<string, string> dict = new Dictionary<string, string>();
            if (data != null && data.Count>0)
            {
                foreach (string key in data.Keys)
                {
                    dict[key] = Convert.ToString(data[key]);
                }
            }
            return await WebHostService.Current.Invoker.InvokeAsync(base.HttpContext, dict);
        }
    }
}
#endif